package top.codedance.iotp.client.plugins.sync.db.oracle;

import com.alibaba.fastjson.JSONObject;
import top.codedance.iotp.client.ClientApplication;
import top.codedance.iotp.common.executer.SyncAbstractExecuter;
import top.codedance.iotp.common.entity.PluginResultEntity;
import org.apache.log4j.Logger;

import java.nio.charset.StandardCharsets;

public class OracleExecuterImpl extends SyncAbstractExecuter {
    private Logger logger = ClientApplication.getLogger(OracleExecuterImpl.class);

    @Override
    public PluginResultEntity exec(byte[] data, String taskId) {
        PluginResultEntity result = new PluginResultEntity();
        try {
            String str = new String(data, StandardCharsets.UTF_8);
            JSONObject client = JSONObject.parseObject(str);
            Integer clientId = client.getInteger("id");
            String sql = client.getString("sql");
            result = new DBUtil(getIniConfig()).executeQuery(clientId, sql);
        } catch (Exception e) {
            logger.debug(e.getMessage());
            result.setOk(false);
            result.setMsg(e.getMessage());
        }
        return result;
    }
}
